package cn.ibdsr.human.controller;

import cn.ibdsr.human.constant.GenderEnum;
import cn.ibdsr.human.constant.JwtConstants;
import cn.ibdsr.human.constant.Result;
import cn.ibdsr.human.db.mapper.*;
import cn.ibdsr.human.db.model.*;
import cn.ibdsr.human.transfer.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @description:
 * @author: cdl
 * @email: iamcimon@qq.com
 * @date: 2021/8/5 13:30
 */
@Api(tags = "下拉列表控制器")
@RestController
@RequestMapping(value = "/commons")
@Slf4j
@Validated
public class CommonController {
    @Resource
    private EducationMapper educationMapper;
    @Resource
    private PoliticMapper politicMapper;
    @Resource
    private MarryMapper marryMapper;
    @Resource
    private ExperienceMapper experienceMapper;
    @Resource
    private WorkerTypeMapper workerTypeMapper;

    @Resource
    private CompanyProperMapper companyProperMapper;
    /**
     * cdl-ok
     * 获取教育程度列表
     */
    @ApiOperation("获取教育程度列表")
    @GetMapping("/educations")
    @ResponseBody
    public Result<EducationDTO> getEducations(@RequestParam("isLimit") Boolean isLimit) {
        QueryWrapper<Education> queryWrapper = new QueryWrapper<>();
        List<Education> educationList = educationMapper.selectList(queryWrapper);
        EducationDTO educationDTO = new EducationDTO();
        List<StringDTO> educations = new ArrayList<>();
        if(isLimit){
            StringDTO stringDTO = new StringDTO();
            stringDTO.setText(JwtConstants.NO_LIMIT);
            stringDTO.setValue(0L);
            educations.add(stringDTO);
        }
        for (int i = 0; i < educationList.size(); i++) {
            StringDTO stringDTO = new StringDTO();
            stringDTO.setText(educationList.get(i).getName());
            stringDTO.setValue(educationList.get(i).getId());
            educations.add(stringDTO);
        }
        educationDTO.setEducations(educations);
        return new Result<>(educationDTO);
    }


    /**
     * cdl-ok
     * 获取教育程度列表
     */
    @ApiOperation("获取结婚情况列表")
    @GetMapping("/marries")
    @ResponseBody
    public Result<MarryDTO> getMarries(@RequestParam("isLimit") Boolean isLimit) {
        QueryWrapper<Marry> queryWrapper = new QueryWrapper<>();
        List<Marry> marries = marryMapper.selectList(queryWrapper);
        MarryDTO marryDTO = new MarryDTO();
        List<StringDTO> stringDTOS = new ArrayList<>();

        if(isLimit){
            StringDTO stringDTO = new StringDTO();
            stringDTO.setText(JwtConstants.NO_LIMIT);
            stringDTO.setValue(0L);
            stringDTOS.add(stringDTO);
        }

        for (int i = 0; i < marries.size(); i++) {
            StringDTO stringDTO = new StringDTO();
            stringDTO.setText(marries.get(i).getName());
            stringDTO.setValue(marries.get(i).getId());
            stringDTOS.add(stringDTO);
        }
        marryDTO.setMarries(stringDTOS);
        return new Result<>(marryDTO);
    }


    /**
     * cdl-ok
     * 获取教育程度列表
     */
    @ApiOperation("获取政治面貌列表")
    @GetMapping("/politics")
    @ResponseBody
    public Result<PoliticDTO> getPolitics(@RequestParam("isLimit") Boolean isLimit) {
        QueryWrapper<Politic> queryWrapper = new QueryWrapper<>();
        List<Politic> politics = politicMapper.selectList(queryWrapper);
        PoliticDTO politicDTO = new PoliticDTO();
        List<StringDTO> stringDTOS = new ArrayList<>();


        if(isLimit){
            StringDTO stringDTO = new StringDTO();
            stringDTO.setText(JwtConstants.NO_LIMIT);
            stringDTO.setValue(0L);
            stringDTOS.add(stringDTO);
        }


        for (int i = 0; i < politics.size(); i++) {
            StringDTO stringDTO = new StringDTO();
            stringDTO.setText(politics.get(i).getName());
            stringDTO.setValue(politics.get(i).getId());
            stringDTOS.add(stringDTO);
        }
        politicDTO.setPolitics(stringDTOS);
        return new Result<>(politicDTO);
    }


    /**
     * cdl-ok
     * 获取性别列表
     */
    @ApiOperation("获取性别列表")
    @GetMapping("/genders")
    @ResponseBody
    public Result<GenderDTO> getGenders(@RequestParam("isLimit") Boolean isLimit) {
        GenderDTO genderDTO = new GenderDTO();
        List<StringDTO> stringDTOS = new ArrayList<>();

        StringDTO NOLIMIT = new StringDTO();
        NOLIMIT.setText(GenderEnum.NO_LIMIT.getDesc());
        NOLIMIT.setValue(GenderEnum.NO_LIMIT.getType()*1L);
        stringDTOS.add(NOLIMIT);

        StringDTO man = new StringDTO();
        man.setText(GenderEnum.MAN.getDesc());
        man.setValue(GenderEnum.MAN.getType()*1L);
        stringDTOS.add(man);
        StringDTO woman = new StringDTO();
        woman.setText(GenderEnum.WOMAN.getDesc());
        woman.setValue(GenderEnum.WOMAN.getType()*1L);
        stringDTOS.add(woman);
        genderDTO.setGenders(stringDTOS);
        return new Result<>(genderDTO);
    }
    /**
     * cdl-ok
     * 获取性别列表
     */
    @ApiOperation("获取经验列表")
    @GetMapping("/experiences")
    @ResponseBody
    public Result<ExperienceDTO> getExperiences(@RequestParam("isLimit") Boolean isLimit) {
        ExperienceDTO experienceDTO = new ExperienceDTO();
        QueryWrapper<Experience> experienceQueryWrapper = new QueryWrapper<>();
        List<Experience> experiences = experienceMapper.selectList(experienceQueryWrapper);
        List<StringDTO> stringDTOS = new ArrayList<>();

        if(isLimit){
            StringDTO stringDTO = new StringDTO();
            stringDTO.setText(JwtConstants.NO_LIMIT);
            stringDTO.setValue(0L);
            stringDTOS.add(stringDTO);
        }

        for (int i = 0; i < experiences.size(); i++) {
            StringDTO stringDTO = new StringDTO();
            stringDTO.setText(experiences.get(i).getName());
            stringDTO.setValue(experiences.get(i).getId());
            stringDTOS.add(stringDTO);
        }
        experienceDTO.setExperiences(stringDTOS);
        return new Result<>(experienceDTO);
    }

    /**
     * cdl-ok
     * 获取性别列表
     */
    @ApiOperation("获取工作类型")
    @GetMapping("/work-types")
    @ResponseBody
    public Result<WorkTypeDTO> getWorkTypes(@RequestParam("isLimit") Boolean isLimit) {
        WorkTypeDTO workTypeDTO = new WorkTypeDTO();

        QueryWrapper<WorkerType> workerTypeQueryWrapper = new QueryWrapper<>();
        List<WorkerType> workerTypes = workerTypeMapper.selectList(workerTypeQueryWrapper);
        List<StringDTO> stringDTOS = new ArrayList<>();


        if(isLimit){
            StringDTO stringDTO = new StringDTO();
            stringDTO.setText(JwtConstants.NO_LIMIT);
            stringDTO.setValue(0L);
            stringDTOS.add(stringDTO);
        }

        for (int i = 0; i < workerTypes.size(); i++) {
            StringDTO stringDTO = new StringDTO();
            stringDTO.setText(workerTypes.get(i).getName());
            stringDTO.setValue(workerTypes.get(i).getId());
            stringDTOS.add(stringDTO);
        }
        workTypeDTO.setWorkTypes(stringDTOS);
        return new Result<>(workTypeDTO);
    }

    /**
     * cdl-ok
     * 获取性别列表
     */
    @ApiOperation("获取企业性质")
    @GetMapping("/company-propers")
    @ResponseBody
    public Result<CompanyProperDTO> getCompanyPropers(@RequestParam("isLimit") Boolean isLimit) {
        CompanyProperDTO companyProperDTO = new CompanyProperDTO();
        QueryWrapper<CompanyProper> companyProperQueryWrapper = new QueryWrapper<>();
        List<CompanyProper> companyPropers = companyProperMapper.selectList(companyProperQueryWrapper);
        List<StringDTO> stringDTOS = new ArrayList<>();

        if(isLimit){
            StringDTO stringDTO = new StringDTO();
            stringDTO.setText(JwtConstants.NO_LIMIT);
            stringDTO.setValue(0L);
            stringDTOS.add(stringDTO);
        }

        for (int i = 0; i < companyPropers.size(); i++) {
            StringDTO stringDTO = new StringDTO();
            stringDTO.setText(companyPropers.get(i).getName());
            stringDTO.setValue(companyPropers.get(i).getId());
            stringDTOS.add(stringDTO);
        }
        companyProperDTO.setCompanyPropers(stringDTOS);
        return new Result<>(companyProperDTO);
    }
}
